package com.seu.vcampus.app;

import com.seu.vcampus.server.VCampusServer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 虚拟校园服务器启动类
 * 
 * @author 虚拟校园开发团队
 * @since 1.0.0
 */
public class VCampusServerApplication {
    private static final Logger logger = LoggerFactory.getLogger(VCampusServerApplication.class);
    
    public static void main(String[] args) {
        logger.info("启动虚拟校园服务器...");
        
        int port = 8888;
        if (args.length > 0) {
            try {
                port = Integer.parseInt(args[0]);
            } catch (NumberFormatException e) {
                logger.warn("无效的端口号，使用默认端口 8888");
            }
        }
        
        VCampusServer server = new VCampusServer(port);
        server.start();
        
        // 添加关闭钩子
        Runtime.getRuntime().addShutdownHook(new Thread(() -> {
            logger.info("正在关闭服务器...");
            server.stop();
        }));
    }
}